/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import com.etfbl.net.dao.DAODrzava;
import com.etfbl.net.dao.DAOEvent;
import com.etfbl.net.dao.DAOUser;
import com.etfbl.net.dto.Drzava;
import com.etfbl.net.dto.Event;
import com.etfbl.net.dto.EventPK;
import com.etfbl.net.dto.User;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author abosancic
 */
public class JavaApplication1 {

    public static void main(String[] args) throws
            ClassNotFoundException, SQLException, Exception{
//        DAOUser per = new DAOUser();
//        List<User> liu = new ArrayList<User>();
//        liu = per.findAll();
//        System.out.println(" " + liu.size());
        
//        liu = per.select("select * from user");
//        per.remove("DELETE FROM user WHERE id BETWEEN ? AND ?", 3, 500001);
//        ResultSet res = per.selectResultSet("select * from user");
//        while (res.next()) {
//                User u = new User();
//                u.setId(res.getInt(1));
//                u.setUsername(res.getString(2));
//                u.setPassword(res.getString(3));
//                u.setEmail(res.getString(4));
//                u.setIdAdrese(res.getInt(5));
//                u.setIdStatusa(res.getInt(6));
//                liu.add(u);
//            }
            
//            System.out.println(" " + liu.size());
    
//        for (int i = 3; i < 500001; i++) {
//            User u = new User();
//            u.setId(i);
//            u.setUsername("username" + i);
//            u.setPassword("password" + i);
//            u.setEmail("email");
//            u.setIdAdrese(1);
//            u.setIdStatusa(1);
//            liu.add(u);
//        }
//        per.save(liu);
//        
//        if(liu != null)
//        {
//            if(liu.size() > 0)
//            {
//                System.out.println("user: " + liu.get(0).getUsername());
//            }
//        }
//        System.out.println("user: " + per.countRows());
        
//        System.out.println("Number of users: " + 
//                per.select("select u.*, mu.* " +
//                        "   from user as u , " +
//                        "   (select m.id as mid, m.naziv as mna, a.id as aid, a.naziv as ana from mjesto as m , adresa a where m.id = a.idmjesta) as mu " +
//                        "where u.idAdrese = mu.aid"));
       
//        DAOMjesto pmj = new DAOMjesto();
//        
//        System.out.println("Number of mjestos: " + 
//                pmj.selectResultSet("select distinct mu.mid as id, mu.mna as naziv, mu.mop as opis, mu.mdr as iddrzave " +
//                        "   from user as u , " +
//                        "   (select m.id as mid, m.naziv as mna, m.opis as mop, m.iddrzave as mdr, a.id as aid, a.naziv as ana from mjesto as m , adresa a where m.id = a.idmjesta) as mu " +
//                        "where u.idAdrese = mu.aid"));
//
//        DAODrzava drz = new DAODrzava();
//        System.out.println("Number of mjestos: " + 
//                drz.select("select d.* from drzava as d, "
//                + " (select distinct mu.mid as id, mu.mna as naziv, mu.mop as opis, mu.mdr as iddrzave " +
//                        "   from user as u , " +
//                        "   (select m.id as mid, m.naziv as mna, m.opis as mop, m.iddrzave as mdr, a.id as aid, a.naziv as ana from mjesto as m , adresa a where m.id = a.idmjesta) as mu " +
//                        "where u.idAdrese = mu.aid) as mje "
//                + "where d.iddrzave = mje.iddrzave"));
//        
//        DAOMjesto mj = new DAOMjesto();
//        System.out.println("Number of mjestos: " + 
//                mj.select("select distinct m.* from mjesto as m, "
//                        + "(select a.id as aid from adresa as a, user as u where u.idAdrese = a.id) as ua "
//                        + "where m.id = ua.aid"));
//        
//        System.out.println("Number of mjestos: " + 
//                mj.select("select distinct m.* from mjesto as m, "
//                        + "(select a.id as aid from adresa as a, user as u where u.idAdrese = a.id) as ua "
//                        + "where m.id = ?", "1"));
//     
//        ResultSet res = pmj.selectResultSet("select m.* from mjesto m, adresa a where m.id = a.idmjesta");
//        System.out.println("Number of mjestos: " + res);
//        
//        while (res.next()) {
//            int column = res.getMetaData().getColumnCount();
//            
//            for (int i = 1; i <= column; i++) {
//                System.out.print(" " + res.getString(i));
//            }
//            
//            System.out.println();
//        }
        
//        res = mj.selectResultSet("select u.* from mjesto m, adresa a, user u where m.id = a.idmjesta and u.idAdrese = a.id and u.id = ?", "1");
//        System.out.println("Number of mjestos: " + res);
//        
//        while (res.next()) {
//            int column = res.getMetaData().getColumnCount();
//            
//            for (int i = 1; i <= column; i++) {
//                System.out.print(" " + res.getString(i));
//            }
//            
//            System.out.println();
//        }
        
        DAOEvent dao = new DAOEvent();
//        EventPK pk = new EventPK("ee-dd3", 1);
//        Event ev = dao.find(pk);
//        System.out.println(ev);
//        
//        ev = dao.getLast();
//        System.out.println(ev);
//        
        DAODrzava dr = new DAODrzava();

        while (true) {            
            
        Scanner s = new Scanner(System.in);
        s.next();
        
        long start = System.nanoTime();
        // do stuff
        List<Event> evets = dao.findAll();
        
        Drzava d = dr.find(5);
        System.out.println(d);
        
        System.out.println("--- findAll() ---");
//        for (Event event : evets) {
//            System.out.println(event);
//        }
        System.out.println("--- end ---");
        
        long end = System.nanoTime();
        long microseconds = (end - start)/1000;
        microseconds /= 1000;
        
        System.out.println("   elapse time: " + microseconds);
        } 
//        evets = dao.findByName("abosancic");
//        System.out.println("--- findByName() ---");
//        for (Event event : evets) {
//            System.out.println(event);
//        }
//        System.out.println("--- end ---");
        
//        System.out.println("--- remove(PK) ---");
//        EventPK remove = new EventPK("aa-bb4", 4);
//        System.out.println("remove: " + dao.remove(remove));
//        System.out.println("--- end ---");
        
//        for (int i = 7; i < 777; i++) {
//        System.out.println("--- save() ---");
//        Event save = new Event();
//        save.setGuid("dd-aa");
//        save.setIdevent(778);
//        save.setName("novi dogadjaj ");
//        save.setDate( new Timestamp(Calendar.getInstance().getTimeInMillis()) );
//        System.out.println("save: " + dao.save(save));
//        System.out.println("--- end ---");
//        }
        
//        System.out.println("--- remove(T object) ---");
//        EventPK get = new EventPK("aa-bb", 4);
//        Event rem = dao.find(get);
//        System.out.println("remove: " + dao.remove(rem));
//        System.out.println("--- end ---");
        
//        System.out.println("--- update(T object) ---");
//        get = new EventPK("aa-bb-", 3);
//        Event update = dao.find(get);
//        update.setName("update new name !!!!!");
//        System.out.println("update: " + dao.update(update) );
//        System.out.println("--- end ---");
        
    }
}